package com.qf.blogsystem.service.impl;

import com.qf.blogsystem.core.dao.BaseDao;
import com.qf.blogsystem.core.service.impl.BaseServiceImpl;
import com.qf.blogsystem.dao.CommentDao;
import com.qf.blogsystem.dao.impl.CommentDaoImpl;
import com.qf.blogsystem.entity.Comment;
import com.qf.blogsystem.service.CommentService;
import com.qf.blogsystem.vo.CommentVo;

import java.util.Date;
import java.util.List;

/**
 * @author Crazy
 * @version 1.0
 * @description: 评论业务层实现类
 * @date 2022/12/6 11:47
 */
public class CommentServiceImpl extends BaseServiceImpl<Comment> implements CommentService {
    /**
     * 创建评论Dao实现类对象
     */
    private CommentDao commentDao=new CommentDaoImpl();

    @Override
    protected BaseDao<Comment> getBaseDao() {
        return commentDao;
    }

    /**
     * 添加评论信息
     * @param comment
     * @return boolean
     * @throws Exception
     */
    @Override
    public boolean save(Comment comment) throws Exception {
        comment.setStatus(0);
        comment.setCreateTime(new Date());
        return super.save(comment);
    }

    /**
     * 根据被评论的实体id查询评论信息
     * @param entityType
     * @param entityId
     * @return List<CommentVo>
     * @throws Exception
     */
    @Override
    public List<CommentVo> commentListByEntityId(Integer entityType, Integer entityId) throws Exception {
        return commentDao.selectCommentByEntityId(entityType,entityId);
    }
}
